//
//  Ext+UIBarButtonItem.swift
//  SwiftDemoWithSina
//
//  Created by qu on 2017/1/17.
//  Copyright © 2017年 Apple. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    convenience init(imageName: String? = nil,title: String? = nil, target: Any?, action: Selector) {
       self.init()
        let btn = UIButton()
        btn.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
        if let image = imageName {
            btn.setImage(UIImage(named:image), for: UIControlState.normal)
            btn.setImage(UIImage(named:"\(image)_highlighted"), for: UIControlState.highlighted)
        }
        if let tit = title {
            btn.setTitle(tit, for: UIControlState.normal)
            btn.setTitleColor(UIColor.darkGray, for: UIControlState.normal)
            btn.setTitleColor(KCOlOR, for: UIControlState.highlighted)
            btn.titleLabel?.font = UIFont.systemFont(ofSize: 15)
            btn.setTitleColor(UIColor.lightGray, for: UIControlState.disabled)
        }
        
        btn.sizeToFit()
        customView = btn
        
    }

}
